package com.ruoyi.mapper;

import com.ruoyi.domain.AdvOrders;
import com.ruoyi.domain.OrderStatisticsDTO;
import com.ruoyi.domain.Vo.AdvIncomeVo;
import com.ruoyi.enums.OrderStatusEnum;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;

/**
 * product_imageMapper接口
 *
 * @author ruoyi
 * @date 2024-05-13
 */
public interface AdvOrdersMapper
{

    @Delete("delete from  adv_orders")
    public int clear();

    @Delete("delete from adv_orders   where adv_members_id=#{advMembersId}")
    public int deleteByAdvMembersId(@Param("advMembersId") String advMembersId);
    /**
     * 查询product_image
     *
     * @param advOrdersId product_image主键
     * @return product_image
     */
    public AdvOrders selectAdvOrdersByAdvOrdersId(Long advOrdersId);

    /**
     * 查询product_image列表
     *
     * @param advOrders product_image
     * @return product_image集合
     */
    public List<AdvOrders> selectAdvOrdersList(AdvOrders advOrders);

    /**
     * 新增product_image
     *
     * @param advOrders product_image
     * @return 结果
     */
    public int insertAdvOrders(AdvOrders advOrders);

    /**
     * 修改product_image
     *
     * @param advOrders product_image
     * @return 结果
     */
    public int updateAdvOrders(AdvOrders advOrders);

    /**
     * 删除product_image
     *
     * @param advOrdersId product_image主键
     * @return 结果
     */
    public int deleteAdvOrdersByAdvOrdersId(Long advOrdersId);

    /**
     * 批量删除product_image
     *
     * @param advOrdersIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteAdvOrdersByAdvOrdersIds(Long[] advOrdersIds);

    /**
     * 根据时间区间获取订单
     */
    public List<AdvOrders> findOrderByTime(AdvIncomeVo advIncomeVo);

    @Update("update adv_orders set bal_flag = '1' where adv_orders_id = #{orderId}")
    public Boolean updateBalFlag(@Param("orderId") Long orderId);

    List<AdvOrders> findUnsettled(Long advMembersId);

    //获取近一周的交易统计
    List<OrderStatisticsDTO> findOrdersOfLastWeek();

    //发货保存物流单号及公司
    int updateBySendGoods(AdvOrders advOrders);

//    //发货保存物流单号在出入库
//    int updateByOutInSendGoods(AdvOrders advOrders);

    //存储支付id
    void savePrepayId(@Param("advOrdersId") Long advOrdersId,@Param("prepayId") String prepayId);

    //获取订单状态
    String getOrderStatus(@Param("ordersno") String ordersno);

    //更新支付成功订单状态
    void updateStatusByOrder(@Param("ordersno")String ordersno,@Param("orderStatus") String orderStatus,@Param("fundContent") String fundContent,@Param("transactionId") String transactionId,@Param("advOrdersPayDate")String advOrdersPayDate);

    //更新退款申请内容
    void updateStatusByOrderRefund(@Param("ordersno")String ordersno,@Param("orderStatus") String orderStatus,@Param("refundContent") String refundContent,@Param("outRefundNo") String outRefundNo);

    //更新微信退款号和订单状态
    void updateStatusByOrderRefundId(@Param("ordersno")String ordersno,@Param("orderStatus") String orderStatus,@Param("refundContent") String refundContent,@Param("refundId") String refundId);

    //拒绝退款
    void updateStatusByOrderNotRefund(@Param("remark") String remark,@Param("advOrdersId") Long advOrdersId,@Param("orderStatus") String orderOver);

    //    获取传递时间未支付的订单
    List<AdvOrders> getNoPayOrderByDuration(@Param("instant")Instant instant);

    //根据订单号查询未支付的订单
    AdvOrders getNoPayOrderByAdvOrdersId(@Param("advOrdersId") Long advOrdersId);

    //根据订单号查询已经支付的订单
    AdvOrders getPayOrderByAdvOrdersId(@Param("advOrdersId") Long advOrdersId);

    // 查询状态为已发货且发货日期超过 N 天的订单
    List<AdvOrders> findOrdersByStatusAndSendDateBefore(@Param("orderStatus") String orderStatus,@Param("advSenddate") LocalDateTime advSenddate);

    //定时任务： 更新订单状态
    void updateOrderStatusAndConfirmDate(@Param("advOrdersId") Long advOrdersId,@Param("orderStatus") String orderStatus,@Param("advConfirmdate") LocalDateTime advConfirmdate);


    @Update("update adv_orders set order_status=4 where adv_orders_id=#{advOrdersId}")
    int isGet(@Param("advOrdersId") String advOrdersId);

    /**
     * 更新此订单的订单编号
     * @param ordersno
     * @param advOrdersId
     */
    void updateOrderNoByNewOder(@Param("ordersno") String ordersno,@Param("advOrdersId") Long advOrdersId);

    /**
     * 小程序不分页查询订单
     * @param advOrders
     * @return
     */
    List<AdvOrders> selectAllByAppOrderList(AdvOrders advOrders);

    /**
     * 更新退款状态
     * @param advOrdersId
     * @param orderStatus
     */
    void exeRequestOrderRefund(@Param("advOrdersId") Long advOrdersId,@Param("orderStatus") String orderStatus);

    /**
     *  退换货
     * @param advOrders
     */
    void exeGoodsChange(AdvOrders advOrders);

    /**
     * 通过 id查询Order
     * @param advOrdersId
     * @return
     */
    AdvOrders selectOrderPayByOrderId(@Param("advOrdersId") Long advOrdersId);

    //通过收益id查询所有订单数据
    List<AdvOrders> selShare(@Param("advIncomeId") Long advIncomeId);

    @Select("select adv_orders_id as advOrdersId from adv_orders where ref_ordersno = #{ordersno}")
    AdvOrders selectByRefOrdersno(@Param("ordersno") String ordersno);

    List<AdvOrders> findOrdersByPayButNotSendGoods(String type, LocalDateTime sevenDaysAgo);
}
